//
//  BusinessVideoCell.m
//  BaseProject
//
//  Created by 王洋 on 2020/7/4.
//  Copyright © 2020 王洋. All rights reserved.
//
#import <SDWebImage/SDWebImage.h>

#import "BusinessVideoCell.h"

@implementation BusinessVideoCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        //self.contentView.backgroundColor = UIColor.whiteColor;
        //self.backgroundColor = UIColor.whiteColor;
        [self contentView];
    }
    return self;
}
- (void)layoutSubviews {
    [super layoutSubviews];
    
    WEAKSELF
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [weakSelf.coverImageView pp_clipCorners:UIRectCornerAllCorners radius:6];
    });
}

- (void)fillCellWithModel:(CommonMediaModel *)model {
    
    self.model = model;
    __block UIImage *placeholderImage = [UIImage imageNamed:@"placeholder"];
    WEAKSELF
    [[SDImageCache sharedImageCache] diskImageExistsWithKey:self.model.videoCover completion:^(BOOL isInCache) {
        __typeof(&*weakSelf) strongSelf = weakSelf;
        if (isInCache) {
            //本地存在图片,替换占位图片
            placeholderImage = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:model.videoCover];
        }
        [strongSelf.coverImageView sd_setImageWithURL:[NSURL URLWithString:model.videoCover] placeholderImage:placeholderImage];
    }];
}

//- (void)setModel:(CommonMediaModel *)model {
//
//}

- (IBAction)playAction:(id)sender {
    if (_delegate && [_delegate respondsToSelector:@selector(cl_tableViewCellPlayVideoWithCell:)]){
        [_delegate cl_tableViewCellPlayVideoWithCell:self];
    }
}


@end
